package com.hzit.bj1804.dianservice.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hzit.bj1804.dian.entity.Productcategory;
import com.hzit.bj1804.dian.vo.MemberPage;
import com.hzit.bj1804.dianservice.dao.ProductcategoryDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.List;
@Service
public class ProductategoryServiceImpl implements ProductategoryService {
    @Autowired
    private ProductcategoryDAO productcategoryDAO;

    /**
     *查询所有类别
     * @return
     */
    @Override
    public List<Productcategory> findAllType() {
        List<Productcategory> productcategoryList = productcategoryDAO.selectAllProductcategory();
        return productcategoryList;
    }

    /**
     * 分页查询所有类别
     * @param limit
     * @param page
     * @return
     */
    @Override
    public PageInfo<Productcategory> findAllTypePage(@RequestParam("limit") int limit, @RequestParam("page") int page) {
        PageHelper.startPage(page,limit);
        List<Productcategory> list = productcategoryDAO.selectAllProductcategory();
        return new PageInfo<>(list);
    }

    /**
     * 根据类别ID查询
     * @param categoryid
     * @return
     */
    @Override
    public List<Productcategory> findById(@RequestParam("categoryid") int categoryid) {

        return productcategoryDAO.selectByPrimaryByid(categoryid);
    }

    /**
     * 根据类别名模糊查询
     * @param categoryname
     * @return
     */
    @Override
    public List<Productcategory> findByIdAndName(@RequestParam("categoryname") String categoryname) {
        List<Productcategory> list = productcategoryDAO.selectByProductcategory(categoryname);
        return list;
    }

    /**
     * 修改类别信息
     * @param productcategory
     * @return
     */
    @Override
    public int updateProductcatgoryType(Productcategory productcategory) {
        int i = productcategoryDAO.updateByPrimaryKeySelective(productcategory);
        return i;
    }

    /**
     * 添加类别信息
     * @param productcategory
     * @return
     */
    @Override
    public int addProductcatgoryType(Productcategory productcategory) {
        int i = productcategoryDAO.insertSelective(productcategory);
        return i;
    }

    /**
     * 根据类别删除（修改）ID，只修改状态和是否显示
     * @param categoryid
     * @return
     */
    @Override
    public int deletProducatgoryStatus(int categoryid) {
        Productcategory productcategory = productcategoryDAO.selectByPrimaryKey(categoryid);
        if (productcategory.getStatus()==1){
            productcategory.setShow("0");
            productcategory.setStatus((short)0);
            int i = productcategoryDAO.updateByPrimaryKeySelective(productcategory);
            System.out.println(i+"---->修改成功！");
            return i;
        }else {
            System.out.println("修改失败！");
            return 0;
        }

    }
}
